home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2003 June / macformat-130.iso / mac / Reviewed⁄Demos / Spearhead Demo / demota / pak1.pk3 / global / friendlytank.scr < prev    next >
Encoding:
Text File  |  2002-10-21  |  3.0 KB  |  124 lines

  1. //-----------------------------------------------------------------
  2. //    FriendlyTank.Scr
  3. //    Jeff Leggett
  4. //    
  5. //    Friendly tank AI...
  6. //
  7. //    Usage:
  8. //    To get it going:
  9. //        $mytank thread global/FriendlyTank.Scr::FriendlyTankStart $german_tanks empty_tiger
  10. //
  11. //    If you want to stop it:
  12. //        $mytank thread global/FriendlyTank.Scr::FriendlyTankStop:
  13. //
  14. //    To drive a path and stop when it gets there:
  15. //
  16. //        $mytank thread global/FriendlyTank.scr::DrivePath local.path local.speed local.lookahead local.remove
  17. //
  18. //
  19. //-----------------------------------------------------------------
  20.  
  21. //-----------------------------------------------------------------
  22. main:
  23. //-----------------------------------------------------------------
  24.  
  25.     End
  26.  
  27.  
  28. //-----------------------------------------------------------------
  29. FriendlyTankStart local.enemyname local.type:
  30. //
  31. //        See the tank_killed function in vehicles_thinkers.scr to 
  32. //    see the meaning of local.type...
  33. //-----------------------------------------------------------------
  34.  
  35.     self.attackthread    = local
  36.  
  37.     if (local.type!=NIL)
  38.         self.type            = local.type
  39.     else
  40.         self.type            = empty_tiger
  41.  
  42.     self.gun = self QueryTurretSlotEntity 0
  43.     self removeondeath 0
  44.  
  45.     self thread WaitForDeath
  46.     self thread global/vehicles_thinkers.scr::tank_pain self.gun 0
  47.  
  48.     // setup our explosion...
  49.  
  50.     while (isAlive self)
  51.     {
  52.         self waitthread FindTarget local.enemyname
  53.         self.gun waittill ontarget
  54.         wait 0.4
  55.  
  56.         if ( isAlive self )
  57.             self.gun anim fire
  58.         
  59.         wait 2
  60.     }
  61.  
  62.     End
  63.  
  64. //-----------------------------------------------------------------
  65. FriendlyTankStop:
  66. //-----------------------------------------------------------------
  67.  
  68.     if ( self.attackthread )
  69.     {
  70.         self.attackthread delete
  71.         self.attackthread = NULL
  72.     }
  73.  
  74.     End
  75.  
  76. //-----------------------------------------------------------------
  77. FindTarget local.enemyname:
  78. //
  79. //    Find a random target with the passed enemyname and target it...
  80. //-----------------------------------------------------------------
  81.  
  82.     if ( local.enemyname==NIL )
  83.     {
  84.         println "Invalid enemyname in FriendlyTank.scr"
  85.         End
  86.     }
  87.  
  88.     // get 1-based random #
  89.     local.random = randomint local.enemyname.size-1
  90.     local.random++
  91.  
  92.     // get main turret.
  93.     self.gun = self QueryTurretSlotEntity 0
  94.     self.gun setAimTarget local.enemyname[local.random]
  95.  
  96.     End
  97.  
  98. //-----------------------------------------------------------------
  99. DrivePath local.path local.speed local.lookahead local.remove:
  100. //-----------------------------------------------------------------
  101.     self.driving = 1
  102.     self drive local.path local.speed 30 200 level.lookahead
  103.     self waittill drive
  104.     if (self)
  105.     {
  106.         self stop
  107.         self.driving = 0
  108.         if (local.remove == "remove")
  109.             self remove
  110.     }
  111.     
  112.     End
  113.  
  114. //-----------------------------------------------------------------
  115. WaitForDeath:
  116. //
  117. //    Does all the great explosion stuff when we blow up...
  118. //-----------------------------------------------------------------
  119.  
  120.     self waittill death
  121.     self waitthread global/vehicles_thinkers.scr::tank_killed
  122.  
  123.     End
  124.